<div class="layui-fluid" lay-title="在线用户">
  <div class="layui-row layui-col-space15">
    <div class="layui-card">
      <div class="layui-card-header">
        <i class="layui-icon layui-icon-team"></i>&nbsp;在线用户
      </div>
      <div class="layui-card-body">
        <table id="online_user_table" lay-filter="online_user_table"></table>
      </div>
    </div>
  </div>
</div>

<script>
  layui.use(["admin", "table"], function(admin, table) {
    var $ = layui.$;
    var table = layui.table;
    var laydate = layui.laydate;

    kickUser = function(loginName) {
      layer.confirm(
        "确定要将当前会话强制下线吗？<br>用户名：" + loginName,
        { icon: 3, title: "强制用户下线" },
        function(index) {
          admin.post({
            api: "kickOnlineUser",
            data: { loginName: loginName },
            success: function(res) {
              if (res.data == true) {
                layer.alert("操作成功！");
              } else {
                layer.alert("操作失败！");
              }
            }
          });
        }
      );
    };

    // 渲染表格实例
    var query_history_tableIns = table.render({
      elem: "#online_user_table",
      url: "ucenter/online_user", //数据接口
      cols: [
        [
          {
            title: "序号",
            width: 80,
            align: "center",
            templet: function(d) {
              return d.LAY_TABLE_INDEX + 1;
            }
          },
          {
            field: "sessionId",
            title: "会话ID",
            width: 180,
            align: "center"
          },
          {
            field: "uid",
            title: "用户UID",
            width: 180,
            align: "center"
          },
          {
            field: "loginName",
            title: "用户名",
            mWidth: 160,
            align: "center"
          },
          {
            field: "userName",
            title: "用户姓名",
            mWidth: 200,
            align: "center"
          },
          {
            field: "deptName",
            title: "机构",
            mWidth: 220,
            align: "center"
          },
          {
            field: "host",
            title: "登录IP",
            width: 140,
            align: "center"
          },
          {
            field: "loginTime",
            title: "登录时间",
            width: 160,
            align: "center"
          },
          {
            field: "lastAccessTime",
            title: "最后请求时间",
            width: 160,
            align: "center"
          },
          {
            title: "操作",
            width: 90,
            align: "center",
            templet: function(d) {
              return (
                "<button class='layui-btn layui-btn-danger layui-btn-xs' onclick='kickUser(\"" +
                d.loginName +
                "\")'>强制下线</button>"
              );
            }
          }
        ]
      ]
    });
  });
</script>
